#include <iostream>
#include <string>
#include <map>

using std::map;
using std::string;
using std::cout;
using std::endl;
bool func(const string& s,const string& t)
{
    if(s.size() != t.size()) return false;
    map<char,int> ms;
    map<char,int> mt;

    for(int i = 0;i < s.size();++ i)
    {
        char sc = s[i];
        char tc = t[i];

        ms.count(sc) == 0 ? ms[sc] = 1 : ++ ms[sc];
        mt.count(tc) == 0 ? mt[tc] = 1 : ++ mt[tc];
    }

    for(auto &it : ms)
    {
        if(ms[it.first] != mt[it.first]) return false;
    }

    return true;
}

int main(int argc, char const *argv[])
{
    string s = "anagram";
    string t = "nagaram";

    bool ret = func(s,t);
    cout << "ret:" << ret << endl;
    getchar();
    return 0;
}
